package com.teamone.etl.util;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Description
 * @Author ZhaoPeiJie
 * @Date 2021/1/21 11:42
 * @Version 1.0
 */
public class SendSmsUtil {
    private static String REGIONID = "cn-hangzhou";
    private static String SignName = "宋氏学习网站";
    private static String TemplateCode = "SMS_206737755";
    private static String AccessKeyId = "";
    private static String Secret = "";
    private static final int INITIALCAPACITY = 16;
    private static final int START = 0;
    private static final int STOP = 4;

    public static void sendSms(String warningPhone) {
        DefaultProfile profile = DefaultProfile.getProfile(REGIONID, AccessKeyId, Secret);
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", REGIONID);
        request.putQueryParameter("PhoneNumbers", warningPhone);
        request.putQueryParameter("SignName", SignName);
        request.putQueryParameter("TemplateCode", TemplateCode);

        Map<String, Object> map = new HashMap<>(INITIALCAPACITY);
        String code = UUID.randomUUID().toString().substring(START, STOP);
        map.put("code",code);
        try {
            request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
